package h0718;

import java.util.*;
/**
  * @description TODO 开源项目热度榜单
  * @author 不知名帅哥
  * @date 2024/7/18 22:57
  * @version 1.0
*/
public class OpenSourceProject {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());  //n个项目
        //权重
//        int[] weights = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] weights=new int[5];
        for (int i = 0; i < 5; i++) {
            weights[i]= sc.nextInt();
        }

        sc.nextLine();  //注意吞掉回车
        String[][] arr = new String[n][6];
        //存入一个二维数组 字符串 热度值
        String[][] heats=new String[n][2];

        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextLine().split(" ");
            int sum=0;
            for (int j = 1; j < arr[i].length; j++) {
                sum+=Integer.parseInt(arr[i][j])*weights[j-1];
            }
            heats[i][0]=arr[i][0];
            heats[i][1]=String.valueOf(sum);
        }

        Arrays.sort(heats, new Comparator<String[]>() {
            @Override
            public int compare(String[] a, String[] b) {
                int n1 = Integer.parseInt(a[1]);
                int n2 = Integer.parseInt(b[1]);
                if (n1!=n2){
                    return n2-n1;   //从大到小排序，热度值降序
                }else {
                    String s1 = a[0].toLowerCase();
                    String s2=b[0].toLowerCase();
                    return s1.compareTo(s2);
                }
            }
        });
        for (String[] heat : heats) {
            System.out.println(heat[0].toLowerCase());
        }
    }
}
